package com.yunfei.api.financialCalculator.service;
import com.yunfei.api.financialCalculator.param.TongjiCalParam;
import com.yunfei.api.financialCalculator.result.TongjiCalResult;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.enums.ResultStatus;
import com.yunfei.enums.TongJiCalResultStatus;
import com.yunfei.procedure.TongJiCalProcedure;
import com.yunfei.utils.jdbc.AiiidbUtil;
import com.yunfei.utils.string.StringUtil;
import org.springframework.core.env.Environment;
public class TongJiCalService {
    //统计计算器接口
    public static ResultModel cal(TongjiCalParam param, Environment env){
        ResultModel resultModel=new ResultModel();
        String pairCnt=param.getPairCnt();
        String onePair=param.getOnePair();
        String twoPair=param.getTwoPair();
        //参数校验
        if(StringUtil.isNullOrEmpty(pairCnt)){
            resultModel.setCode(TongJiCalResultStatus.pairCnt.getCode());
            resultModel.setMessage(TongJiCalResultStatus.pairCnt.getMessage());
            return resultModel;
        }
        if(StringUtil.isNullOrEmpty(onePair)){
            resultModel.setCode(TongJiCalResultStatus.onePair.getCode());
            resultModel.setMessage(TongJiCalResultStatus.onePair.getMessage());
            return resultModel;
        }
        if(StringUtil.isNullOrEmpty(twoPair)){
            resultModel.setCode(TongJiCalResultStatus.twoPair.getCode());
            resultModel.setMessage(TongJiCalResultStatus.twoPair.getMessage());
            return resultModel;
        }
        //获取数据库连接
        AiiidbUtil aiiidbUtil=AiiidbUtil.getInstance(env);
        //调用处处过程
        TongjiCalResult result=new TongJiCalProcedure().callProcedure(aiiidbUtil,param);
        resultModel.setData(result);
        resultModel.setCode(ResultStatus.SUCCESS.getCode());
        resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        return resultModel;
    }
}
